//
//  WYHistoryController.m
//  CirclePush
//
//  Created by admin on 2018/4/16.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYHistoryController.h"
#import "WYRecommendCell.h"
#import "UIButton+WYButton.h"
@interface WYHistoryController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation WYHistoryController
-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self loadData];
}
-(void)setupUI
{
    [self initTopBarWithTitle:self.titleName];
    [self addLeftButton:[UIImage imageNamed:@"return"] width:0 height:0];
//    [self addRightButton:[UIImage imageNamed:@"return"] width:0 height:0];
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYRecommendCell" bundle:nil] forCellReuseIdentifier:@"WYRecommendCell"];
    self.tableView.tableFooterView = [[UIView alloc]init];
}
-(void)loadData
{
    WEAKSELF
    [WYHttpServer getMediaListWithHistoryOrCollect:self.history WithPageNum:@"1" WithPageSize:@"10" SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            if ([WYMedia getMediaListFromJson:response[@"result"]].count) {
                [weakSelf.dataArray addObject:[WYMedia getMediaListFromJson:response[@"result"]]];
                [weakSelf.tableView reloadData];
                [self.tableView.mj_footer endRefreshing];
            }
            
        }else{
            
        }
        
        
        
        
    }];
    
    
    
}
//-(void)leftButtonPress
//{
//    [self.rightButton showBadgeOnItemIndex];
//}
//-(void)rightButtonPress
//{
//    [self.rightButton hideBadgeOnItemIndex];
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataArray[section]count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WYRecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYRecommendCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"WYRecommendCell" owner:nil options:nil].firstObject;
    }
    WYMedia *media = self.dataArray[indexPath.section][indexPath.row];
    [cell setMedia:media];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.frame = CGRectMake(0, NavHeight, kScreenWidth, kScreenHeight-NAV_HEIGHT);
    }
    return _tableView;
}




@end
